﻿// -----------------------------------------------------------------------
// <copyright file="NodeWorkflowData.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Reflection;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    using VDC.VONE.ENTITIES;
    
    /// <summary>
    /// Class access to db NodeWorkflow
    /// </summary>
    public class NodeWorkflowData
    {
        /// <summary>
        /// Get NodeWorkflow By Id
        /// </summary>
        /// <param name="nodeWorkflowId">Param nodeWorkflowId</param>
        /// <returns>Return NodeWorkflow</returns>
        public NodeWorkflowEN GetNodeWorkflowById(int nodeWorkflowId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                NodeWorkflowEN nodeWorkflow = null;
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowGetById, nodeWorkflowId);
                while (reader.Read())
                {
                    nodeWorkflow = new NodeWorkflowEN();

                    if (!reader.IsDBNull(0))
                    {
                        nodeWorkflow.NodeWorkflowId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        nodeWorkflow.WorkflowId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        nodeWorkflow.NodeId = reader.GetInt32(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        nodeWorkflow.ConditionsId = reader.GetInt32(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        nodeWorkflow.NextNodeId = reader.GetInt32(4);
                    }

                    if (!reader.IsDBNull(5))
                    {
                        nodeWorkflow.ProfileTypeProgressId = reader.GetInt32(5);
                    }

                    if (!reader.IsDBNull(6))
                    {
                        nodeWorkflow.ProfileStatusId = reader.GetInt32(6);
                    }

                    if (!reader.IsDBNull(7))
                    {
                        nodeWorkflow.Orders = reader.GetInt32(7);
                    }

                    if (!reader.IsDBNull(8))
                    {
                        nodeWorkflow.Send = reader.GetString(8);
                    }

                    if (!reader.IsDBNull(9))
                    {
                        nodeWorkflow.PrintReceipt = reader.GetBoolean(9);
                    }

                    if (!reader.IsDBNull(10))
                    {
                        nodeWorkflow.PrintVotehandover = reader.GetBoolean(10);
                    }

                    if (!reader.IsDBNull(11))
                    {
                        nodeWorkflow.Rw = reader.GetBoolean(11);
                    }
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return nodeWorkflow;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Get list all NodeWorkflow
        /// </summary>
        /// <returns>Return list all NodeWorkflow</returns>
        public IList<NodeWorkflowEN> GetNodeWorkflows()
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<NodeWorkflowEN> lstNodeWorkflow = new List<NodeWorkflowEN>();
                SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowGetAll);
                while (reader.Read())
                {
                    NodeWorkflowEN nodeWorkflow = new NodeWorkflowEN();

                    if (!reader.IsDBNull(0))
                    {
                        nodeWorkflow.NodeWorkflowId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        nodeWorkflow.WorkflowId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        nodeWorkflow.NodeId = reader.GetInt32(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        nodeWorkflow.ConditionsId = reader.GetInt32(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        nodeWorkflow.NextNodeId = reader.GetInt32(4);
                    }

                    if (!reader.IsDBNull(5))
                    {
                        nodeWorkflow.ProfileTypeProgressId = reader.GetInt32(5);
                    }

                    if (!reader.IsDBNull(6))
                    {
                        nodeWorkflow.ProfileStatusId = reader.GetInt32(6);
                    }

                    if (!reader.IsDBNull(7))
                    {
                        nodeWorkflow.Orders = reader.GetInt32(7);
                    }

                    if (!reader.IsDBNull(8))
                    {
                        nodeWorkflow.Send = reader.GetString(8);
                    }

                    if (!reader.IsDBNull(9))
                    {
                        nodeWorkflow.PrintReceipt = reader.GetBoolean(9);
                    }

                    if (!reader.IsDBNull(10))
                    {
                        nodeWorkflow.PrintVotehandover = reader.GetBoolean(10);
                    }

                    if (!reader.IsDBNull(11))
                    {
                        nodeWorkflow.Rw = reader.GetBoolean(11);
                    }

                    lstNodeWorkflow.Add(nodeWorkflow);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstNodeWorkflow;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Insert to db NodeWorkflow
        /// </summary>
        /// <param name="nodeWorkflow">Paarm NodeWorkflow</param>
        /// <returns>Insert NodeWorkflow</returns>
        public int Insert(NodeWorkflowEN nodeWorkflow)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var sqlParameters = new[]
                                {
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.WorkflowId, nodeWorkflow.WorkflowId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.NodeId, nodeWorkflow.NodeId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.ConditionsId, nodeWorkflow.ConditionsId != 0 ? nodeWorkflow.ConditionsId : (object)DBNull.Value),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.NextNodeId, nodeWorkflow.NextNodeId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.ProfileTypeProgressId, nodeWorkflow.ProfileTypeProgressId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.ProfileStatusId, nodeWorkflow.ProfileStatusId != 0 ? nodeWorkflow.ProfileStatusId : (object)DBNull.Value),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.Orders, nodeWorkflow.Orders != 0 ? nodeWorkflow.Orders : (object)DBNull.Value),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.Send, string.IsNullOrEmpty(nodeWorkflow.Send) ? (object)DBNull.Value : nodeWorkflow.Send),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.PrintReceipt, nodeWorkflow.PrintReceipt),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.PrintVotehandover, nodeWorkflow.PrintVotehandover),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.Rw, nodeWorkflow.Rw)
                                };

                var result = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowInsert, sqlParameters));
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return result;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Update to db NodeWorkflow
        /// </summary>
        /// <param name="nodeWorkflow">Param NodeWorkflow</param>
        public void Update(NodeWorkflowEN nodeWorkflow)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var sqlParameters = new[]
                                {
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.NodeWorkflowId, nodeWorkflow.NodeWorkflowId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.WorkflowId, nodeWorkflow.WorkflowId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.NodeId, nodeWorkflow.NodeId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.ConditionsId, nodeWorkflow.ConditionsId != 0 ? nodeWorkflow.ConditionsId : (object)DBNull.Value),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.NextNodeId, nodeWorkflow.NextNodeId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.ProfileTypeProgressId, nodeWorkflow.ProfileTypeProgressId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.ProfileStatusId, nodeWorkflow.ProfileStatusId),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.Orders, nodeWorkflow.Orders),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.Send, string.IsNullOrEmpty(nodeWorkflow.Send) ? (object)DBNull.Value : nodeWorkflow.Send),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.PrintReceipt, nodeWorkflow.PrintReceipt),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.PrintVotehandover, nodeWorkflow.PrintVotehandover),
                                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.Rw, nodeWorkflow.Rw)
                                };

                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowUpdate, sqlParameters);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Delete NodeWorkflow by nodeWorkflowId
        /// </summary>
        /// <param name="nodeWorkflowId">param nodeWorkflowId</param>
        public void Delete(int nodeWorkflowId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var sqlParameters = new[] 
                { 
                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.NodeWorkflowId, nodeWorkflowId)
                };

                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowDelete, sqlParameters);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Delete NodeWorkflow
        /// </summary>
        /// <param name="nodeWorkflowId">param nodeWorkflowId</param>
        public void DeleteNodeWorkflowandDefault(int nodeWorkflowId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var sqlParameters = new[] 
                { 
                    new SqlParameter(Constants.SqlParamerterName.NodeWorkflow.NodeWorkflowId, nodeWorkflowId)
                };

                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowDeleteNodeWorkflow, sqlParameters);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Get List NodeWorkflow By WorkflowId
        /// </summary>
        /// <param name="workflowId">Param workflowId</param>
        /// <returns>Return List NodeWorkflow</returns>
        public IList<NodeWorkflowEN> GetNodeWorkflowByWorkflowId(int workflowId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<NodeWorkflowEN> lstNodeWorkflow = new List<NodeWorkflowEN>();
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowGetByWorkflowId, workflowId);
                while (reader.Read())
                {
                    NodeWorkflowEN nodeWorkflow = new NodeWorkflowEN();

                    if (!reader.IsDBNull(0))
                    {
                        nodeWorkflow.NodeWorkflowId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        nodeWorkflow.WorkflowId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        nodeWorkflow.NodeId = reader.GetInt32(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        nodeWorkflow.ConditionsId = reader.GetInt32(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        nodeWorkflow.NextNodeId = reader.GetInt32(4);
                    }

                    if (!reader.IsDBNull(5))
                    {
                        nodeWorkflow.ProfileTypeProgressId = reader.GetInt32(5);
                    }

                    if (!reader.IsDBNull(6))
                    {
                        nodeWorkflow.ProfileStatusId = reader.GetInt32(6);
                    }

                    if (!reader.IsDBNull(7))
                    {
                        nodeWorkflow.Orders = reader.GetInt32(7);
                    }

                    if (!reader.IsDBNull(8))
                    {
                        nodeWorkflow.Send = reader.GetString(8);
                    }

                    if (!reader.IsDBNull(9))
                    {
                        nodeWorkflow.PrintReceipt = reader.GetBoolean(9);
                    }

                    if (!reader.IsDBNull(10))
                    {
                        nodeWorkflow.PrintVotehandover = reader.GetBoolean(10);
                    }

                    if (!reader.IsDBNull(11))
                    {
                        nodeWorkflow.Rw = reader.GetBoolean(11);
                    }

                    lstNodeWorkflow.Add(nodeWorkflow);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstNodeWorkflow;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Get List NodeWorkflow By NodeId
        /// </summary>
        /// <param name="nodeId">Param nodeId</param>
        /// <returns>Return List NodeWorkflow</returns>
        public IList<NodeWorkflowEN> GetNodeWorkflowByNodeId(int nodeId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<NodeWorkflowEN> lstNodeWorkflow = new List<NodeWorkflowEN>();
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowGetByNodeId, nodeId);
                while (reader.Read())
                {
                    NodeWorkflowEN nodeWorkflow = new NodeWorkflowEN();

                    if (!reader.IsDBNull(0))
                    {
                        nodeWorkflow.NodeWorkflowId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        nodeWorkflow.WorkflowId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        nodeWorkflow.NodeId = reader.GetInt32(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        nodeWorkflow.ConditionsId = reader.GetInt32(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        nodeWorkflow.NextNodeId = reader.GetInt32(4);
                    }

                    if (!reader.IsDBNull(5))
                    {
                        nodeWorkflow.ProfileTypeProgressId = reader.GetInt32(5);
                    }

                    if (!reader.IsDBNull(6))
                    {
                        nodeWorkflow.ProfileStatusId = reader.GetInt32(6);
                    }

                    if (!reader.IsDBNull(7))
                    {
                        nodeWorkflow.Orders = reader.GetInt32(7);
                    }

                    if (!reader.IsDBNull(8))
                    {
                        nodeWorkflow.Send = reader.GetString(8);
                    }

                    if (!reader.IsDBNull(9))
                    {
                        nodeWorkflow.PrintReceipt = reader.GetBoolean(9);
                    }

                    if (!reader.IsDBNull(10))
                    {
                        nodeWorkflow.PrintVotehandover = reader.GetBoolean(10);
                    }

                    if (!reader.IsDBNull(11))
                    {
                        nodeWorkflow.Rw = reader.GetBoolean(11);
                    }

                    lstNodeWorkflow.Add(nodeWorkflow);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstNodeWorkflow;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Gets the node workflow by workflow_ node.
        /// </summary>
        /// <param name="workflowId">The workflow id.</param>
        /// <param name="nodeId">The node id.</param>
        /// <returns>Return NodeWorkflow</returns>
        public IList<NodeWorkflowEN> GetNodeWorkflowByWorkflow_Node(int workflowId, int nodeId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<NodeWorkflowEN> lstNodeWorkflow = new List<NodeWorkflowEN>();
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowGetByWorkflowNode, workflowId, nodeId);
                while (reader.Read())
                {
                    NodeWorkflowEN nodeWorkflow = new NodeWorkflowEN();

                    if (!reader.IsDBNull(0))
                    {
                        nodeWorkflow.NodeWorkflowId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        nodeWorkflow.WorkflowId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        nodeWorkflow.NodeId = reader.GetInt32(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        nodeWorkflow.ConditionsId = reader.GetInt32(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        nodeWorkflow.NextNodeId = reader.GetInt32(4);
                    }

                    if (!reader.IsDBNull(5))
                    {
                        nodeWorkflow.ProfileTypeProgressId = reader.GetInt32(5);
                    }

                    if (!reader.IsDBNull(6))
                    {
                        nodeWorkflow.ProfileStatusId = reader.GetInt32(6);
                    }

                    if (!reader.IsDBNull(7))
                    {
                        nodeWorkflow.Orders = reader.GetInt32(7);
                    }

                    if (!reader.IsDBNull(8))
                    {
                        nodeWorkflow.Send = reader.GetString(8);
                    }

                    if (!reader.IsDBNull(9))
                    {
                        nodeWorkflow.PrintReceipt = reader.GetBoolean(9);
                    }

                    if (!reader.IsDBNull(10))
                    {
                        nodeWorkflow.PrintVotehandover = reader.GetBoolean(10);
                    }

                    if (!reader.IsDBNull(11))
                    {
                        nodeWorkflow.Rw = reader.GetBoolean(11);
                    }

                    lstNodeWorkflow.Add(nodeWorkflow);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstNodeWorkflow;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Get Node by next Node
        /// </summary>
        /// <param name="nodeId">param nodeId</param>
        /// <returns>Return List</returns>
        public IList<NodeWorkflowEN> GetNodeWorkflowByNextNodeId(int nodeId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                IList<NodeWorkflowEN> lstNodeWorkflow = new List<NodeWorkflowEN>();
                var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowGetByNextNodeId, nodeId);
                while (reader.Read())
                {
                    NodeWorkflowEN nodeWorkflow = new NodeWorkflowEN();

                    if (!reader.IsDBNull(0))
                    {
                        nodeWorkflow.NodeWorkflowId = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        nodeWorkflow.WorkflowId = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        nodeWorkflow.NodeId = reader.GetInt32(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        nodeWorkflow.ConditionsId = reader.GetInt32(3);
                    }

                    if (!reader.IsDBNull(4))
                    {
                        nodeWorkflow.NextNodeId = reader.GetInt32(4);
                    }

                    if (!reader.IsDBNull(5))
                    {
                        nodeWorkflow.ProfileTypeProgressId = reader.GetInt32(5);
                    }

                    if (!reader.IsDBNull(6))
                    {
                        nodeWorkflow.ProfileStatusId = reader.GetInt32(6);
                    }

                    if (!reader.IsDBNull(7))
                        {
                            nodeWorkflow.Orders = reader.GetInt32(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            nodeWorkflow.Send = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            nodeWorkflow.PrintReceipt = reader.GetBoolean(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            nodeWorkflow.PrintVotehandover = reader.GetBoolean(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            nodeWorkflow.Rw = reader.GetBoolean(11);
                        }

                    lstNodeWorkflow.Add(nodeWorkflow);
                }

                reader.Close();
                reader.Dispose();
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return lstNodeWorkflow;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Exist Order
        /// </summary>
        /// <param name="workflowId">Param profileTypeId</param>
        /// <param name="orders">Param progressId</param>
        /// <returns>positionData.Exist(profileTypeId, progressId)</returns>
        public bool Exist(int workflowId, int orders)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var result = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, Constants.StorepProcedure.VOnenodeWorkflowOrderExist, workflowId, orders));
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return result > 0;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        /// Check Exist NodeWorkflow When Add, Edit
        /// </summary>
        /// <param name="workfolowId">param nodeWorkflowId</param>
        /// <param name="nodeWorkflowId">param nodeWorkflowId</param>
        /// <param name="nodeId">param nodeId</param>
        /// <param name="conditionsId">param conditionsId</param>
        /// <returns>return result</returns>
        public bool Exist(int workfolowId, int nodeWorkflowId, int nodeId, int conditionsId)
        {
            string methodName = MethodBase.GetCurrentMethod().DeclaringType.ToString() + Constants.Dot + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                var result = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowExist, workfolowId, nodeWorkflowId, nodeId, conditionsId == -1 ? (object)DBNull.Value : conditionsId));
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                return result > 0;
            }
            catch (SqlException ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);
                throw new Exception(ex.ToString());
            }
        }
    }
}